<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: yangzg
 * @Date: 2022-08-16 16:28:32
 * @LastEditors: wangmiao
 * @LastEditTime: 2022-08-31 11:11:06
-->
<template>
  <div class="container">
    <el-dialog v-model="isShow" width="30%" center>
      <div class="content">
        <h1>设置奖励</h1>
        <div class="rewardOption">
          <div class="rewardInfo">
            <el-radio-group v-model="radioValue" class="ml-4">
              <el-radio
                v-for="(item, index) in rewardData"
                :key="item.id"
                :label="item.id"
                size="large"
                >{{ `奖励${index + 1} ${item.name}` }}</el-radio
              >
            </el-radio-group>
          </div>
        </div>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button
            @click="saveOrCancel(dialogClickType.determine)"
            type="primary"
            >确定</el-button
          >
          <el-button @click="saveOrCancel(dialogClickType.cancel)"
            >取消</el-button
          >
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { dialogClickType, setBtnType } from "@/constants/const.ts";
// import { rewardList } from "./data.ts";
import { formType, temInfoType } from "@/models/add_problem_type.ts";
import { PRO_VARIABLE, TEST_VARIABLE } from "@/constants/env.ts";
import { guid } from "@/utils/index.ts";
import { getReWards } from "@/service/home/home.ts";
import { problemInfo } from "@/models/home.ts";

interface Props {
  detailedInfo: problemInfo;
  componentType: string;
  isEdit?: true;
  itemInfo?: temInfoType;
  AppId: string;
}

const {
  AppId,
  problemTypeList,
  componentType,
  isEdit,
  itemInfo,
  detailedInfo,
} = defineProps<Props>();

const emit = defineEmits(["getChildValue"]);

const isShow = ref<boolean>(true);

const radioValue = ref("");
radioValue.value = detailedInfo.RewardType || "";

// 获取奖励list
let rewardData = ref([]);
const getReWardList = async () => {
  // 正式查安康的馆， 测试时菜馆的馆
  const res = await getReWards({
    AppId:
      import.meta.env.VITE_APP_ENV === PRO_VARIABLE
        ? "2fd5f092-d360-4783-b95c-6d47ee5cac44"
        : "26623574-04f5-4a44-848e-84ea81677e16",
  });
  if (res.IsSuccess) {
    rewardData.value = res.Content;
  } else {
    rewardData.value = [];
  }
};
getReWardList();

const saveOrCancel = (type) => {
  if (type === dialogClickType.determine) {
    emit("getChildValue", {
      type: setBtnType.rewardSet,
      btnType: dialogClickType.determine,
      rewardItem: rewardData.value.find((item) => item.id === radioValue.value),
    });
  } else {
    emit("getChildValue", {
      type: setBtnType.rewardSet,
      btnType: dialogClickType.cancel,
    });
  }
};
</script>

<style lang="scss" scoped>
@import "./index.scss";
</style>
